﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhDataAcess.orderLinqDAL;
using dhSystemBLL.orderData;

namespace dhsystem.orderForm
{
    public partial class FrmPbomDetailAdd : Form
    {

        pbomDetailBLL pbomDetail = new pbomDetailBLL();
        pbomDetailModel pbomDetailRow = new pbomDetailModel();
        productListBLL productList = new productListBLL();
        materialListBLL materialList = new materialListBLL();
        BindingSource BindingSourceDetailAdd;
        string state;
        string productname;
        //绑定数据源
        public FrmPbomDetailAdd(BindingSource bindingSourcepbomDetail, string _state, string _productname)
        {
            InitializeComponent();
            BindingSourceDetailAdd = bindingSourcepbomDetail;
            state = _state;
            productname = _productname;

        }
        ////绑定数据源
        //public FrmPbomDetailAdd(BindingSource bindingSourcepbomDetail, string _state)
        //{
        //    InitializeComponent();
        //    BindingSourceDetailAdd = bindingSourcepbomDetail;
        //    state = _state;
           
        //}
        //打开窗口时绑定数据
        private void FrmPbomDetailAdd_Load(object sender, EventArgs e)
        {
          

                bindingSourcematerialList.DataSource = materialList.getmaterialListAll();
                comboBoxmatNum.DataSource = bindingSourcematerialList;
                comboBoxmatNum.DisplayMember = "matNum";
                comboBoxmatNum.ValueMember = "matNum";
              if (state == "编辑")
              {
                textproductname.DataBindings.Add("text", BindingSourceDetailAdd, "pname");
                textWb.DataBindings.Add("text", BindingSourceDetailAdd, "wb");
                comboBoxmatNum.DataBindings.Add("text", BindingSourceDetailAdd, "matNum");
                textPt.DataBindings.Add("text", BindingSourceDetailAdd, "pt");
                textPz.DataBindings.Add("text", BindingSourceDetailAdd, "pz");
                textTs.DataBindings.Add("text", BindingSourceDetailAdd, "ts");
                textblen.DataBindings.Add("text", BindingSourceDetailAdd, "blen");
                textPweight.DataBindings.Add("text", BindingSourceDetailAdd, "pweight");
                textAlen.DataBindings.Add("text", BindingSourceDetailAdd, "alen");
                textAweight.DataBindings.Add("text", BindingSourceDetailAdd, "aweight");
                textmark.DataBindings.Add("text", BindingSourceDetailAdd, "mark");
                textid.DataBindings.Add("text", BindingSourceDetailAdd, "recordid");
             // BindingSourceDetailAdd.AddNew();
               //textproductname.Text = productname;
           }
             if (state == "新增")
            {
                textproductname.DataBindings.Add("text", BindingSourceDetailAdd, "pname");
                textWb.DataBindings.Add("text", BindingSourceDetailAdd, "wb");
                comboBoxmatNum.DataBindings.Add("text", BindingSourceDetailAdd, "matNum");
                textPt.DataBindings.Add("text", BindingSourceDetailAdd, "pt");
                textPz.DataBindings.Add("text", BindingSourceDetailAdd, "pz");
                textTs.DataBindings.Add("text", BindingSourceDetailAdd, "ts");
                textblen.DataBindings.Add("text", BindingSourceDetailAdd, "blen");
                textPweight.DataBindings.Add("text", BindingSourceDetailAdd, "pweight");
                textAlen.DataBindings.Add("text", BindingSourceDetailAdd, "alen");
                textAweight.DataBindings.Add("text", BindingSourceDetailAdd, "aweight");
                textmark.DataBindings.Add("text", BindingSourceDetailAdd, "mark");
                textid.DataBindings.Add("text", BindingSourceDetailAdd, "recordid");
                BindingSourceDetailAdd.AddNew();
                textproductname.Text = productname;
                comboBoxmatNum.SelectedIndex = 0;
            }

                textWb.Focus();
                



        }
        //保存按钮，插入或修改数据
        private void buttonOK_Click(object sender, EventArgs e)
        {

                try
                {
                    DialogResult result = MessageBox.Show("是否保存资料！", "提示信息", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {

                        BindingSourceDetailAdd.EndEdit(); //编辑到完成，写到数据源
                        BindingSourceDetailAdd.CancelEdit(); //刷新数据作用
                      
                    }
                }
               
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
        }
        //取消按钮
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            BindingSourceDetailAdd.CancelEdit();
            this.Close();
        }

        private void groupAdd_Enter(object sender, EventArgs e)
        {

        }

      

     
    }
}
